import { SetStateAction, useRef, useState } from 'react'
import { postCompanyInfoDetailIcpRecordPageList } from '@/api/companyDetail/intellectual-property'
import { DetailModal } from '@hs-server/components'
import { EMPTYTEXT, useNewPage } from '@hs-admin/utils'
import { HsAdminTablePage } from '@hs-admin/base-components'

const RegistrationWebsite = (props: any) => {
  const { companyCode, hiddenModule } = props
  const columns = [
    {
      title: '序号',
      dataIndex: 'index',
      width: 80,
      render: (_: string, _record: any, index: number) => <>{index + 1 + (pagination.current - 1) * pagination.pageSize}</>
    },
    {
      title: '网站名称',
      dataIndex: 'websiteName'
    },
    {
      title: '网址',
      dataIndex: 'websiteDomain',
      render: (_: string, record: any) => <>{record.websiteList?.properties?.websiteDomain || EMPTYTEXT}</>
    },
    {
      title: '域名',
      dataIndex: 'websiteHome',
      render: (_: string, record: any) => <>{record.websiteList?.properties?.websiteHome || EMPTYTEXT}</>
    },
    {
      title: '网站备案/许可证号',
      dataIndex: 'websiteRecord'
    },
    {
      title: '审核日期',
      dataIndex: 'auditDate'
    }
  ]
  const { pagination } = useNewPage(callList)
  const [data, setdata] = useState([])
  const [iscount, setiscount] = useState('')
  const DetailModalRef = useRef<any>({})
  const [isShow, setIsShow] = useState(false)

  function callList() {
    return postCompanyInfoDetailIcpRecordPageList({
      pageNo: pagination.current,
      pageSize: pagination.pageSize,
      companyCode: companyCode || '16eb79be79b3a2ad79571f1ff7abb6cb'
    }).then((res: { data: { list: SetStateAction<never[]>; total: any } }) => {
      setdata(res.data.list)
      setIsShow(res.data.total ? true : false)
      setiscount(res.data.total ?? '')
      hiddenModule(res.data.total ?? '') //总条数 传给父组件
      return res.data
    })
  }

  return (
    <>
      {isShow && (
        <div className="intellectual-property-registrationWebsite-wrapper" id="备案网站" data-count={iscount}>
          <h3 className="mb-4">备案网站</h3>
          <HsAdminTablePage
            columns={columns}
            dataSource={data}
            id="intellectual-property-registrationWebsite"
            pagination={pagination}
            rowKey={(record: { id: string }) => record.id}
            size="small"
          />
          <DetailModal ref={DetailModalRef} />
        </div>
      )}
    </>
  )
}

export default RegistrationWebsite
